#include "Serialize.h"

char *Serialize::Serialize8(char *ptr, unsigned char value)
{
	*ptr = value;
	return ptr + 1;
}

char *Serialize::Serialize16(char *ptr, unsigned short value)
{
	ptr[1] = (value >> 8) & 0xff;
	ptr[0] = value & 0xff;
	return ptr + 2;
}

char *Serialize::Serialize32(char *ptr, unsigned int value)
{
	ptr[3] = (value >> 24) & 0xff;
	ptr[2] = (value >> 16) & 0xff;
	ptr[1] = (value >> 8) & 0xff;
	ptr[0] = value & 0xff;
	return ptr + 4;
}

char *Serialize::Serialize64(char *ptr, unsigned long long value)
{
	ptr[7] = (value >> 56) & 0xff;
	ptr[6] = (value >> 48) & 0xff;
	ptr[5] = (value >> 40) & 0xff;
	ptr[4] = (value >> 32) & 0xff;
	ptr[3] = (value >> 24) & 0xff;
	ptr[2] = (value >> 16) & 0xff;
	ptr[1] = (value >> 8) & 0xff;
	ptr[0] = value & 0xff;
	return ptr + 8;
}

char *Serialize::Deserialize8(char *ptr, unsigned char &value)
{
	value = *(unsigned char *)ptr;
	return ptr + 1;
}

char *Serialize::Deserialize16(char *ptr, unsigned short &value)
{
	value = *(unsigned short *)ptr;
	return ptr + 2;
}

char *Serialize::Deserialize32(char *ptr, unsigned int &value)
{
	value = *(unsigned int *)ptr;
	return ptr + 4;
}

char *Serialize::Deserialize64(char *ptr, unsigned long long &value)
{
	value = *(unsigned long long *)ptr;
	return ptr + 8;
}